#!/bin/bash

function adoSerilizers()
{
# echo $1
cat >> iClouds/apiSerializers.py <<EOF
class Model$1Serializer(serializers.ModelSerializer):
    class Meta:
        model = $1
        fields = '__all__'

EOF
}


python3 manage.py inspectdb > mysqldb/models.py


cat > iClouds/apiSerializers.py <<'EOF'
from rest_framework import serializers
from rest_framework.serializers import *
from rest_framework.validators import UniqueValidator, UniqueTogetherValidator 
from mysqldb.models import *


EOF

while read -r line; do

re="class ([^/]+)\(models.Model)"

if [[ $line =~ $re ]]; then
    # echo ${BASH_REMATCH[1]}
    adoSerilizers ${BASH_REMATCH[1]}
fi
# echo $line
done < mysqldb/models.py